package iss.java;

import iss.java.list.MyList;
import iss.java.list.Node;
/**
 * Created by wenke on 2016/9/16.
 */
public class Main_B {
    public static void main(String[] args) throws InterruptedException{
        // TODO: Write a multithreaded testcase against requirement B.
        // NOTE: Testcase for requirement C is not required.
        MyList list = new MyList();
        list.insert(list.getHead(), 16);
        list.insert(list.getHead(), 15);
        list.insert(list.getHead(), 14);
        list.insert(list.getHead(), 13);
        list.insert(list.getHead(), 12);
        list.insert(list.getHead(), 11);


        Thread one = new Thread(){              //线程1
            @Override
            public void run() {

                list.insert(list.getHead(), 10);
                list.insert(list.getHead(), 9);
                list.insert(list.getHead(), 8);
                list.insert(list.getHead(), 7);
                list.insert(list.getHead(), 6);
                list.insert(list.getHead(), 5);
            }
        };
        Thread two = new Thread() {            //线程2
            @Override
            public void run(){
                list.remove(list.getHead().getNext());
                list.remove(list.getHead().getNext().getNext());
                list.remove(list.getHead().getNext().getNext().getNext().getNext());
            }
        };
        one.start();
        two.start();
        // Two seconds are enough for the two threads to finish
        Thread.sleep(10000);

        for (Node n = list.getHead().getNext(); n != list.getTail(); n = n.getNext()) {
            System.out.printf("%d ", n.getData());
        }
        System.out.println();

        // Traverse from tail to head, exclude tail and head.
        for (Node n = list.getTail().getPrev(); n != list.getHead(); n = n.getPrev()) {
            System.out.printf("%d ", n.getData());
        }
        System.out.println();

        System.out.println(list.getSize());
    }
}
